/*
 * 图片元素
 * 
 */

var ElementBase = require("./ElementBase.js");

function ElementImg(){
	//继承基类
	ElementBase.apply(this, arguments);
	
	this.type = "img";
	this.url = "";
	this.base64Url = "";
	this.name = "";
}

ElementImg.prototype = new ElementBase();

/*
 * 设置图片信息
 */
ElementImg.prototype.setJson = function($data){
	var self = this;
	this.super_setJson($data);
	this.name = $data.name||"";
	if($data.url){
		self.url = $data.url;
		self.loadImg($data.url, function(img, base64){
			self.base64Url = base64;
			self.element = Design.paper.image(base64);
			self.appendToCon();
			self.createEnd();
		});
	}
}

/*
 * 获取保存的数据
 */
ElementImg.prototype.getSaveData = function() {
	var json = this.super_getSaveData();
	json.url = this.url;
	return json;
}

ElementImg.prototype.getIcon = function(){
	var name = this.name||"图片";
	return '<img alt="" src="'+this.url+'"><span>'+name+'</span>';
}

exports = module.exports = ElementImg;


